#include <opencv2/opencv.hpp>
#include <opencv2/dnn.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>

using namespace cv; //Must Need Write cv
using namespace std;

/*
 * ./opencv_copyTo <logo_pic> <image>
 *
 */

int main(int argc, char** argv)
{
    if (argc < 3) {
        std::cerr << "Usage: " << argv[0] << " <logo_pic>  <image> " << std::endl;
        return -1;
    }
    
    Mat logo_pic = imread(argv[1]);
    if(logo_pic.empty())
    {
        printf("get logo pic err\n");
        return -1;
    }
    else
    {
        printf("width = %d,height = %d,channel = %d \n", logo_pic.cols, logo_pic.rows, logo_pic.channels());
    }

    
    Mat img_src = imread(argv[2]);
    if(img_src.empty())
    {
        printf("get img_src err\n");
        return -1;
    }
    else
    {
        printf("width = %d,height = %d,channel = %d \n", img_src.cols, img_src.rows, img_src.channels());
    }
    
    Mat img_src_roi = img_src(Rect(100, 100, logo_pic.cols, logo_pic.rows));
    if(img_src_roi.empty())
    {
        printf("get img_src_roi  err\n");
        return -1;
    }
    else
    {
        printf("width = %d,height = %d,channel = %d \n", img_src_roi.cols, img_src_roi.rows, img_src_roi.channels());
    }
    
    //注意是logo_pic使用copyTo 
    logo_pic.copyTo(img_src_roi);

    string output_filename = "copyTo.jpg";
        
    bool success = imwrite(output_filename, img_src);
    if (!success) {
        printf("Failed to save image!\n");
        return -1;
    }
    
    return 0;
}


